<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.longtop.com/intelliweb" prefix="e"%>
<%@ page isELIgnored="false"%>
<html>
	<head>
		<title>员工任务批量导入-Iframe-SJH</title>
	</head>
<e:View id="eView" designProperty="width: 1024; height: 768">
	<script type="text/javascript" src="<c:url value='/scripts/global.js'/>"></script>
	<script type="text/javascript" src="<c:url value='/scripts/skin.js'/>"></script>
	<script type="text/javascript" src="<c:url value='/js/perform/perform.js'/>"></script>
	
	<div id="Invisual Controls" style="min-height: 40px;">
	<!--考核阶段 -->
		<e:Dataset id="Dataset_project_segment" pageSize="-1">
			<e:Field name="segmentId" label="分段ID" dataType="string"/>
			<e:Field name="projectId" label="考核方案ID" dataType="string"/>
			<e:Field name="cycleId" label="阶段周期ID" dataType="string"/>
			<e:Field name="segmentName" label="考核阶段名称" dataType="string"/>
			<e:Field name="status" label="状态" dataType="string"/>
			<e:Field name="startDate" label="开始日期" dataType="date"/>
			<e:Field name="endDate" label="结束日期" dataType="date"/>
			<e:Field name="scoreTime" label="计算时间"  dataType="date"/>
			<e:Field name="cycleName" label="阶段周期名称"  dataType="string"/>
		</e:Dataset>
	<!-- 考核方案-指标 -->
		<e:Dataset id="Dataset_project_index" pageSize="-1">
			<e:Field name="projectId" dataType="string"/>
			<e:Field name="indexId" dataType="string"/>
			<e:Field name="indexType" dataType="string"/>
			<e:Field name="indexUnit" dataType="string" label="指标单位"/>
			<e:Field name="scale" dataType="string" label="指标小数位"/>
			<e:Field name="indexName" dataType="string" label="指标名称"/>
		</e:Dataset>		
	<!--任务对应员工-->
		<e:Dataset id="Dataset_task_user" pageSize="-1" confirmDelete="false" confirmCancel="false">
			<e:Field name="taskId" dataType="string" label="任务ID" maxLength="32" visible="false"/>
			<e:Field name="taskName" dataType="string" label="任务名称" maxLength="200" visible="false"/>
			<e:Field name="segmentId" dataType="string" label="考核分段ID" maxLength="32" visible="false"/>
			<e:Field name="userId" dataType="string" label="员工ID" maxLength="32" readOnly="true" />
			<e:Field name="userName" label="员工名称" dataType="string" readOnly="true" />
			<e:Field name="orgName" label="员工所属机构" dataType="string" readOnly="true" />			
		</e:Dataset>
		
		<e:Command id="Command_export" action="com.longtop.perform.khyg.web.TaskAction" method="exportTaskView" showHintInfoOnSuccess="false">
			<e:DatasetInfo name="info" dataset="Dataset_project_index" submitType="all"></e:DatasetInfo>
			<e:Parameter name="segmentId" value=""></e:Parameter>
			<e:Parameter name="isEmptyData" value="true"></e:Parameter>
		</e:Command>	
		<e:Command id="Command_submit" action="com.longtop.perform.khyg.web.TaskAction" method="submitTaskUser">
			<e:DatasetInfo name="info2" dataset="Dataset_project_index" submitType="all" />
			<e:DatasetInfo name="info1" dataset="Dataset_task_user" submitType="all"/>
			<e:Parameter name="submitType" value="all"></e:Parameter>
		</e:Command>					

<body >
<e:Page id="ePage" action="com.longtop.perform.khyg.web.TaskAction" style="min-height: 80px; width: 100%; height: 100%;"  onAfterLoadPage="ePage_onAfterLoadPage()" onBeforeLoadPage="ePage_onBeforeLoadPage()">
	<table width="100%"  border="0" cellpadding="2" cellspacing="2">
		<tr>
			<td>
				<e:GroupBox id="GroupBox_import" caption="上传EXCEL文件">
						<form name="UploadForm" id="UploadForm"action="" method="POST" style="margin: 0px" enctype="multipart/form-data">
							<table width="100%" border="0" cellspacing="2" cellpadding="0">
								<tr>
									<td colspan="3" style="height:25px; color: blue">
										<e:Button id="Button_export" caption="导出模板" onClick="Button_export_onClick('true')" icon="/images/export2.gif" style="height: 22px; width: 85px"></e:Button>&nbsp;&nbsp;&nbsp;
										<e:Button id="Button_exportAll" caption="导出带数据模板" onClick="Button_export_onClick('false')"  icon="/images/export.gif" style="height: 22px; width: 120px"></e:Button>
										* 导入前请先下载模板文件,根据模板文件填写相关信息再导入。
									</td>
								</tr>
								<tr align="left">
									<td noWrap align="right">
										文件选择：
									</td>
									<td noWrap style="width: 80%" align="left">
										<input type="file" name="filename" style="width: 100%; height: 20px" title="单击选择附件" />
									</td>
									<td noWrap align="left" width="99%">
										<e:Button id="Button_import" caption="导入文件" onClick="Button_import_onClick()" icon="/images/import.gif" style="height: 22px; width: 85px"></e:Button>
										<e:Text id="uploadbean" value="userTaskExcel" visible="false"></e:Text><!-- 上传配置的SpringBean 中 的ID -->
									</td>
								</tr>
							</table>
						</form>
					</e:GroupBox>				
			</td>
		</tr>
		<tr>
			<td>
				<table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td height="27px" width="1%">
							<e:RecordNavigator id="RecordNavigator_segmentUser" dataset="Dataset_task_user" showNavigatorButton="false">
								<e:RecordButton id="RecordButton_choose" label="查询考核对象" onClick="RecordButton_choose_onClick()"  icon="/images/query.gif"></e:RecordButton>
            					<e:RecordButton id="RecordButton_save" label="保存数据" onClick="RecordButton_save_onClick()" icon="/images/submit.gif"></e:RecordButton>
							</e:RecordNavigator>
						</td>
						<td align="left" width="99%">
							<div id="importResult"></div>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<!-- 员工任务数据： -->
				<e:Grid id="Grid_segmentUser" style="width: 100%; height: 100%;" showIndex="true" dataset="Dataset_task_user">
				</e:Grid>
			</td>
		</tr>	
	<table>
</e:Page>
</body>
<script language="Javascript">
	//init:
	function ePage_onBeforeLoadPage(){

	}
	function ePage_onAfterLoadPage(){
		var importResult = $J("ePage").tag;
		var importResultDiv = document.getElementById("importResult");
		if(importResult =="importSuccess" ){
			importResultDiv.innerHTML="<font color='blue'>* 导入数据成功，请核对员工任务信息，点击保存数据进行保存。<font/>"
		}else if(importResult =="importFail" ){
			importResultDiv.innerHTML="<font color='red'>* 导入数据存在错误，您可以手动修改员工任务，或则重新导入数据。<font/>"
		}
		
		if($J("Grid_segmentUser").isEmpty()){
			$J("RecordNavigator_segmentUser").setEnabled(false);
			$J("Button_export").setEnabled(false);
			$J("Button_exportAll").setEnabled(false);
			$J("Button_import").setEnabled(false);
			var importResultDiv = document.getElementById("importResult");
			importResultDiv.innerHTML="<font color='red'>* 该考核方案阶段尚未分配任何考核对象。<font/>"
		}
	}
	
	//保存员工任务数据
	function RecordButton_save_onClick(){
		doSave = function (){
			Command_submit.execute();
			document.getElementById("importResult").innerHTML="";
		}
		MsgBox.showConfirmMsg("确定要保存员工任务数据么？","",[doSave]);
	}
	
	//导入数据Excel
	function Button_import_onClick(){
    	var filename=document.getElementById("filename").value;
        if (filename == "") {
            MsgBox.showWarnMsg("请选择要上传的附件。");
            document.getElementById("filename").focus();
            return false;
        }
        if (filename.indexOf(".xls")<0 ) {
             MsgBox.showErrorMsg("只允许上传excel文件。");
            document.getElementById("filename").focus();
            return false;
        }	
        var uploadbean  = document.getElementById('uploadbean').value;
        var winlocation = window.location.toString();
        if(winlocation.indexOf("uploadbean="+uploadbean) != -1){
      		document.getElementById("UploadForm").action = winlocation;
        }else{
        	if(winlocation.indexOf("?")== -1){
        		winlocation = winlocation +"?";
        	}
       	    document.getElementById("UploadForm").action = window.location+"&uploadbean="+uploadbean;
        }
        document.getElementById("UploadForm").submit();
        document.getElementById("UploadForm").reset();
        document.getElementById("UploadForm").action="";       	
	}
	
	//选择考核对象
	function RecordButton_choose_onClick(){
		var segmentId = Dataset_project_segment.getValue('segmentId');		
		var arrayMap = selectTaskUsersFromWindow(segmentId);//选择考核周期对应员工弹出框
		if(arrayMap == ''){
			return;
		}
		var recordArray = Dataset_task_user.records;
		var record;
		for(var j=0; j<recordArray.length; j++){
			record = recordArray.get(j);
			var isExist = false;
			for (var i =0 ; i<arrayMap.length ; i++){
				if(record.getValue("userId") == arrayMap[i].get("userId")){
					isExist = true;
					break;
				}
			}
			if(isExist){//设置选择的员工状态为显示
				Dataset_task_user.setRecordCurrentState(record, Constant.RECORD.NONE);
			}else{
				Dataset_task_user.setRecordCurrentState(record, Constant.RECORD.STATE_DELETE);
			}
		}
		Dataset_task_user.refreshControls();
	}
	
	//导出无数据/带数据excel:
	function Button_export_onClick(isEmptyData){
		var segmentId = Dataset_project_segment.getValue('segmentId');
		Command_export.parameters.setValue("isEmptyData",isEmptyData);		
		Command_export.parameters.setValue("segmentId",segmentId);
		Command_export.execute();
	}
	
</script>
</e:View>
</html>